import axios from 'axios'
// import { getStorage } from '@/utils/storage.js'
import store from '@/store'

const request = axios.create({
  baseURL: 'http://toutiao-app.itheima.net',
  timeout: 3000
})

// 拦截所有利用request发起的请求
request.interceptors.request.use((config) => {
  // config: 当前这次请求的所有配置和请求信息
  // console.log(getStoage('tt-user'))
  if (store.state.user) {
    config.headers.Authorization = 'Bearer ' + store.state.user.token
  }
  return config
})

// 拦截所有响应的结果
request.interceptors.response.use(res => {
  return res.data.data
})

export default request
